package com.richman.view;



import javax.swing.JPanel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;

import com.richman.controller.AutoBetCentralManager;
import com.richman.controller.NegativeRatioClient;
import com.richman.ps38.entity.BetAdyData;
import com.richman.ps38.entity.BetDvalue;
import com.richman.ps38.entity.Event;
import com.richman.ps38.entity.HGEvent;
import com.richman.utils.Common;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class BetLogPane extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8L;
	
	private  Vector<String[]> detailsData = new Vector<String[]>();
	
	private Vector<String[]> detailsDataTmp = new Vector<String[]>(); 
	
	public Vector<Event> gameDetailsVec = new Vector<Event>(); 
	
	private  ReadWriteLock betDvaluesLock = new ReentrantReadWriteLock(); 
	
	
	//BrowserPanel bp = new BrowserPanel();
	
	public static Map<String,String> limitStr = new HashMap<String ,String>();
	
	
	
	MyTableModel tableMode = new MyTableModel();

	
	JTable table = null;

	/**
	 * Create the panel.
	 */
	public BetLogPane() {
		setLayout(new BorderLayout(0, 0));

		JPanel funBtnPane = new JPanel();
		
		JButton cleanButton = new JButton("清空数据");
		cleanButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				int n = JOptionPane.showConfirmDialog(null, "确认要清空数据吗?", "清空数据",
						JOptionPane.YES_NO_OPTION);
				if (n == JOptionPane.YES_OPTION && NegativeRatioClient.betCtrMng != null) {					
					NegativeRatioClient.betCtrMng.clearBetLogData();
				}
				
			}
		});
		
		cleanButton.setBounds(20, 10, 60, 20);
		
		funBtnPane.add(cleanButton);
		
		add(funBtnPane, BorderLayout.NORTH);
		
		
	    table = new JTable(tableMode);
	    
	    table.getColumnModel().getColumn(0).setPreferredWidth(15);
	    
//	    table.getColumnModel().getColumn(2).setPreferredWidth(120);
//	    table.getColumnModel().getColumn(3).setPreferredWidth(130);
//	    table.getColumnModel().getColumn(4).setPreferredWidth(200);
//	    table.getColumnModel().getColumn(5).setPreferredWidth(100);
//	    
//	    
//	    table.getColumnModel().getColumn(8).setPreferredWidth(180);
//	    table.getColumnModel().getColumn(11).setPreferredWidth(180);
	    
	    table.getColumnModel().getColumn(7).setPreferredWidth(210);
	    
	    table.getColumnModel().getColumn(9).setPreferredWidth(100);
	    
	    table.getColumnModel().getColumn(6).setPreferredWidth(30);
	    table.getColumnModel().getColumn(10).setPreferredWidth(20);
	    table.getColumnModel().getColumn(11).setPreferredWidth(30);
	    
	    table.setRowHeight(30);
	    
	    table.setFont(new java.awt.Font("黑体", Font.PLAIN, 15));
		
		

//		
//		TableColumn hgres = table.getColumn("皇冠结果");   
//        TableColumn ps38res = table.getColumn("PS38结果");   
//		
//		
//		
//		
//		
//		
//        DefaultTableCellRenderer resRender = new DefaultTableCellRenderer() {   
//
//            public void setValue(Object value) { //重写setValue方法，从而可以动态设置列单元字体颜色   
//
//               
//            	String str = value.toString();
//            	
//				
//				
//				if(str.contains("成功")){
//					
//					setBackground(Color.GREEN);
//					
//					
//					
//				}else if(str.contains("失败")){
//	
//					setBackground(Color.red);
//				}else {
//					setBackground(Color.yellow);
//				}
//				
//				
//				setForeground(Color.BLACK);
//					
//
//
//            }   
//
//        };   
//		
//        
//        hgres.setCellRenderer(resRender);
//        ps38res.setCellRenderer(resRender);
		
        
		JScrollPane scrollPane = new JScrollPane(table);
		add(scrollPane, BorderLayout.CENTER);
		
		
		
		//add(bp, BorderLayout.SOUTH);
		
		
		
		
		//双击table事件
	    table.addMouseListener(new MouseAdapter(){

            public void mouseClicked(MouseEvent e) {
            	
            	
            	
          	  if(e.getClickCount() == 2){
          		  
          		  
              	  int row =((JTable)e.getSource()).rowAtPoint(e.getPoint()); //获得行位置 
              	
              	  if(row==-1) {
              		  return;
              	  }
              	  if(detailsData.elementAt(row)[11].contains("betCode")
              			  &&!detailsData.elementAt(row)[9].equals("200")
              			  &&!detailsData.elementAt(row)[9].equals("104")){
              		int n = JOptionPane.showConfirmDialog(null, "取消投注: " + detailsData.elementAt(row)[4] + " " + detailsData.elementAt(row)[5] + " " + detailsData.elementAt(row)[6], "取消投注",
    						JOptionPane.YES_NO_OPTION);
    				if (n == JOptionPane.YES_OPTION) {
    					String betID = detailsData.elementAt(row)[11].split(" ")[1];
						NegativeRatioClient.betThread.removeBetVec(betID);
						NegativeRatioClient.betCtrMng.updateBetLog(betID, "104", "");
//    					for(int i = 0;i < NegativeRatioClient.betThread.betVec.size();i++) {
//    						if(NegativeRatioClient.betThread.betVec.elementAt(i).contains(betID)) {
//    							NegativeRatioClient.betThread.removeBetVec(NegativeRatioClient.betThread.betVec.elementAt(i));
//    							NegativeRatioClient.betCtrMng.updateBetLog(betID, "104", "");
//    							break;
//    						}
//    					}
    				}
              	  }
              	  
          	  }else{
          		  return;
          	  }

            }
      });
		

	}
	
	
	
	public void updateBetLogTable(Vector<BetAdyData> gamedetails){
		
		try{
			
			if(detailsData.size() != 0){
				detailsData.clear();
			}
			
			
			if(detailsDataTmp.size() != 0){
				detailsDataTmp.clear();
			}
			
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			int betcount = gamedetails.size();
			
			for(int i = 0; i < gamedetails.size(); i++) {
				
				BetAdyData game = gamedetails.elementAt(i);
				
				String hgbetres = "";
				
				if(game.hgbetres.equals("1")) {
					hgbetres = "成功";
				}else if(game.hgbetres.equals("2")) {
					hgbetres = "确认成功";
				}else if(game.hgbetres.equals("0")) {
					hgbetres = "注单待确认";
				}else if(game.hgbetres.equals("-1")) {
					hgbetres = "超过信用额度";
				}else if(game.hgbetres.equals("-2")) {
					hgbetres = "失败 ";
				}else if(game.hgbetres.equals("-3")) {
					hgbetres = "注单取消，投注失败";
				}else if(game.hgbetres.equals("-4")) {
					hgbetres = "股东限额，投注失败";
					if(!AutoBetCentralManager.limistGames.contains(game.hgeventid)) {
						AutoBetCentralManager.limistGames.add(game.hgeventid);
					}
				}else {
					hgbetres = game.hgbetres;
				}
				
				
				String ps38betres = "";
				String ps38betgold = game.ps38betgold;
				
				if(!game.websitetype.contains("betCode")) {
					if(game.ps38betres.equals("")) {
						ps38betres = "失败";
					}else if(game.ps38betres.equals("2")) {
						ps38betres = "确认成功";
					}else if(game.ps38betres.equals("1")) {
						ps38betres = "成功";
					}else if(game.ps38betres.equals("0")) {
						ps38betres = "注单待确认";
					}else if(game.ps38betres.equals("-3")) {
						ps38betres = "注单取消，投注失败";
					}else if(game.ps38betres.equals("-4")) {
						ps38betres = "注单暂时无法确认,请人工确认";
					}else {
						ps38betres = game.ps38betres;
					}
					
					
				}else {
					if(game.ps38betres.equals("100")) {
						ps38betres = "投注进行中!";
					}else if(game.ps38betres.equals("101")) {
						ps38betres = "成功进注!";
					}else if(game.ps38betres.equals("102")) {
						ps38betres = "目前赔率不符!";
					}else if(game.ps38betres.equals("106")) {
						ps38betres = "注单确认成功!";
					}else if(game.ps38betres.equals("107")) {
						ps38betres = "注单确认取消!";
					}else if(game.ps38betres.equals("108")) {
						ps38betres = "注单等待确认!";
					}else if(game.ps38betres.equals("104")) {
						ps38betres = "已手动取消注单!";
					}else if(game.ps38betres.equals("109")) {
						ps38betres = "软件重启,注单取消!";
					}else if(game.ps38betres.equals("200")) {
						ps38betres = "该投注已完成!";
					}else {
						ps38betres = game.ps38betres+"!";
					}
					
					ps38betgold = "已完成:" + game.ps38betgold + "/" + game.betAmount;
				}
				
				
				
				
				
				if(game.ps38rebetflag != null && game.ps38rebetflag.equals("1")) {
					ps38betres = "补单-" + ps38betres;
				}

				
				
				//{ "序号", "联赛", "时间", "球队", "投注类型", "投注盘口","合并赔率", "皇冠注单", "皇冠金额", "皇冠投注时间","皇冠结果", "PS38注单", "PS38金额 ", "PS38投注时间 ", "PS38结果"};
				String[] item = {Integer.toString(betcount - i),//0
						game.currenttime,
						game.league,
						game.time,
						game.teams,
						game.bettype,//5
						game.betpankou,

						game.ps38bettype,
						ps38betgold,
						ps38betres,
						game.score,
						game.websitetype,//15
						"",
						game.ps38eventid,									
						game.hgeventid,//[18]
						game.hgps38,//[19]
						game.result,
						game.danshipankou,//[21]
						game.danshidaxiao,//[22]
						""};
				
				detailsData.add(0,item);
				
				if(hgbetres.contains("股东限额，投注失败")) {
					detailsDataTmp.add(0,item);
				}

			}
			
			

			for(int i = 0; i < detailsData.size(); i++ ) {
				int limitTimes = 0;
				int limitGold = 0;
				if(detailsData.elementAt(i)[10].contains("股东限额")) {
					
					String outstr = detailsData.elementAt(i)[4] + detailsData.elementAt(i)[5];
					
					for(int j = 0; j <detailsData.size(); j++) {
						
						String instr = detailsData.elementAt(j)[4] + detailsData.elementAt(j)[5];
						
						if(outstr.equals(instr) && detailsData.elementAt(j)[10].contains("股东限额")) {
							limitTimes++;
							limitGold += Integer.parseInt(detailsData.elementAt(j)[9]);
						}
					}
					
					for(int j = 0; j <detailsData.size(); j++) {
						if( outstr.equals(detailsData.elementAt(j)[4] + detailsData.elementAt(j)[4] ) && detailsData.elementAt(j)[10].contains("股东限额") ) {
							detailsData.elementAt(i)[16] = Integer.toString(limitTimes) + "/" + Integer.toString(limitGold);
						}
					}
					
				}
				
				if(limitTimes>0) {
					limitStr.put(detailsData.elementAt(i)[4] + detailsData.elementAt(i)[5] , Integer.toString(limitTimes) + "/" + Integer.toString(limitGold));
				}
			}
			
			
			constructBetLimitDvalue();
			
			setOneRowBackgroundColor();
			
			tableMode.updateTable();

			
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}
	
	
	
	private void constructBetLimitDvalue() {
		
		
		try {
			
			betDvaluesLock.writeLock().lock();
			
			Vector<String> parsealready = new Vector<String>();
			
			
			if(NegativeRatioClient.betCtrMng.betLimitDvalues != null) {
				NegativeRatioClient.betCtrMng.betLimitDvalues.clear();
			}
			
			
			double maxdvalue = NegativeRatioClient.mainWnd.getmaxdvalue();
			
			SimpleDateFormat dfGameTime = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			SimpleDateFormat dfCurrentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			for(int i = 0; i < detailsDataTmp.size(); i++) {
				
				String[] item = detailsDataTmp.elementAt(i);
				
				if(Common.isNum(item[7])) {
					double ratio = Double.parseDouble(item[7]);
					if(ratio - NegativeRatioClient.mainWnd.getbetodd() < 0.0) {
						//投注赔率不超过利润设置则不进行统计
						continue;
	    				
					}
				}
				
				
				if(parsealready.contains(item[18])) {//已经分析过这场球赛
					continue;
				}
				
				
				parsealready.add(item[18]);
				
				
				boolean bfirstpankou = true;
				
				String sfirstpankou = "";
				
				for(int j = detailsDataTmp.size()-1; j >=0; j--) {
					
					
					String[] item1 = detailsDataTmp.elementAt(j);
					
					if(Common.isNum(item1[7])) {
						double ratio = Double.parseDouble(item1[7]);
						if(ratio - NegativeRatioClient.mainWnd.getbetodd() < 0.0) {
							//投注赔率不超过利润设置则不进行统计
							continue;
		    				
						}
					}
					
					String beforeGameTime = "";
					try {
						long tmp1 = dfGameTime.parse(item1[3]).getTime() - dfCurrentTime.parse(item1[1]).getTime();
						tmp1 = tmp1/1000/60;
						beforeGameTime = Long.toString(tmp1);
					}catch(Exception e) {
						
					}
					
					int beforeGameTimeFilter = NegativeRatioClient.mainWnd.getbeforeGameTimeFilter();
					if( Integer.parseInt(beforeGameTime) >beforeGameTimeFilter ) {
						continue; //过滤超出时间范围的注单
					}
					
					if(item1[18].equals(item[18])) {
						
						if(bfirstpankou == true) {						
							
							bfirstpankou = false;
							sfirstpankou = item1[6];
							
							BetDvalue bdvalue = new BetDvalue();
							
							
							bdvalue.time = item1[3];
							bdvalue.league = item1[2];
							bdvalue.team = item1[4];
							bdvalue.betscore = item1[14];
							if(item1[5].contains("让球")) {
								bdvalue.rqbetpankou = item1[6];
								bdvalue.rqbettype = item1[5];
																								
								if(item1[19].equals("1")) {
									if(bdvalue.rqhgps38times==0) {
										bdvalue.rqhgps38timestr = "<html>" + item1[8] + "(" + item1[15] + ")" + beforeGameTime + "<br>";
									}else {
										bdvalue.rqhgps38timestr += item1[8] + "(" + item1[15] + ")" + beforeGameTime + "<br>";
									}
									bdvalue.rqhgps38times++;
								}else if(item1[19].equals("2")) {									
									if(bdvalue.rqps38hgtimes==0) {
										bdvalue.rqps38hgtimestr = "<html>" + item1[8] + "(" + item1[15] + ")" +beforeGameTime + "<br>";
									}else {
										bdvalue.rqps38hgtimestr += item1[8] + "(" + item1[15] + ")" +beforeGameTime + "<br>";
									}
									
									bdvalue.rqps38hgtimes++;
								}
							}else {
								bdvalue.dxbetpankou = item1[6];								
								bdvalue.dxbettype = item1[5];								
								if(item1[19].equals("1")) {									
									if(bdvalue.dxhgps38times==0) {
										bdvalue.dxhgps38timestr = "<html>" + item1[8] + "(" + item1[15] + ")" +beforeGameTime + "<br>";
									}else {
										bdvalue.dxhgps38timestr += item1[8] + "(" + item1[15] + ")" +beforeGameTime + "<br>";
									}
									
									bdvalue.dxhgps38times++;
								}else if(item1[19].equals("2")) {
									
									if(bdvalue.dxps38hgtimes==0) {
										bdvalue.dxps38hgtimestr = "<html>" + item1[8] + "(" + item1[15] + ")" + beforeGameTime +"<br>";
									}else {
										bdvalue.dxps38hgtimestr += item1[8] + "(" + item1[15] + ")" +beforeGameTime + "<br>";
									}
									bdvalue.dxps38hgtimes++;
								}
								
							}
							
							
							
							
							bdvalue.eventid = item1[18];
							bdvalue.result = item1[20];
							
							bdvalue.danshipankou = item1[21];
							bdvalue.danshidaxiao = item1[22];
							
							NegativeRatioClient.betCtrMng.betLimitDvalues.add(bdvalue);
							
							

						}else {
							
							
							if(item1[5].contains("让球")) {
								
								String rqfirstpankou = "";
								boolean first = true;
								boolean find = false;
								
								for(int k = 0; k < NegativeRatioClient.betCtrMng.betLimitDvalues.size(); k++) {
									
									BetDvalue bdvalue = NegativeRatioClient.betCtrMng.betLimitDvalues.elementAt(k);
									
									if(bdvalue.eventid.equals(item1[18]) && 
											bdvalue.rqbettype.length() >=3 &&
									   bdvalue.rqbettype.substring(2).equals(item1[5].substring(2))
									   
									   //DaShuiClient.betCtrMng.betLimitDvalues.elementAt(k).bettype.substring(2).equals(item1[5].substring(2)) &&
									   //Math.abs(Double.parseDouble(DaShuiClient.betCtrMng.betLimitDvalues.elementAt(k).firstpankou) - Double.parseDouble(item1[6])) <= maxdvalue) 
											){
										
										if(first == true) {
											rqfirstpankou = bdvalue.rqbetpankou;
											first = false;
											
										}
										
										
										if( bdvalue.rqbettype.equals(item1[5])&&
												bdvalue.betscore.equals(item1[14]) &&
												   
												   Math.abs(Double.parseDouble(bdvalue.rqbetpankou) - Double.parseDouble(item1[6])) < 0.01) {
											
//											if(item1[19].equals("1")) {
//												bdvalue.rqhgps38times++;
//											}else if(item1[19].equals("2")) {
//												bdvalue.rqps38hgtimes++;
//											}
											
											if(item1[19].equals("1")) {
												if(bdvalue.rqhgps38times==0) {
													bdvalue.rqhgps38timestr = "<html>" + item1[8] + "(" + item1[15] + ")" +beforeGameTime + "<br>";
												}else {
													bdvalue.rqhgps38timestr += item1[8] + "(" + item1[15] + ")" + beforeGameTime +"<br>";
												}
												bdvalue.rqhgps38times++;
											}else if(item1[19].equals("2")) {									
												if(bdvalue.rqps38hgtimes==0) {
													bdvalue.rqps38hgtimestr = "<html>" + item1[8] + "(" + item1[15] + ")" +beforeGameTime + "<br>";
												}else {
													bdvalue.rqps38hgtimestr += item1[8] + "(" + item1[15] + ")" +beforeGameTime + "<br>";
												}
												
												bdvalue.rqps38hgtimes++;
											}
											

											find = true;
											
											break;
											
										}
										

										
									}
									
								}
								
								boolean newtype = false;
								
								if(rqfirstpankou.equals("")) {
									newtype = true;
								}
								
								if( newtype ||
										(find == false && Math.abs(Double.parseDouble(rqfirstpankou) - Double.parseDouble(item1[6])) <= maxdvalue)) {
									BetDvalue newbdvalue = new BetDvalue();
									newbdvalue.betscore = item1[14];
									newbdvalue.rqbettype = item1[5];
									newbdvalue.rqbetpankou = item1[6];
									newbdvalue.eventid = item1[18];
//									if(item1[19].equals("1")) {
//										newbdvalue.rqhgps38times++;
//									}else if(item1[19].equals("2")) {
//										newbdvalue.rqps38hgtimes++;
//									}
									
									if(item1[19].equals("1")) {
										if(newbdvalue.rqhgps38times==0) {
											newbdvalue.rqhgps38timestr = "<html>" + item1[8] + "(" + item1[15] + ")" + beforeGameTime +"<br>";
										}else {
											newbdvalue.rqhgps38timestr += item1[8] + "(" + item1[15] + ")" + beforeGameTime +"<br>";
										}
										newbdvalue.rqhgps38times++;
									}else if(item1[19].equals("2")) {									
										if(newbdvalue.rqps38hgtimes==0) {
											newbdvalue.rqps38hgtimestr = "<html>" + item1[8] + "(" + item1[15] + ")" + beforeGameTime +"<br>";
										}else {
											newbdvalue.rqps38hgtimestr += item1[8] + "(" + item1[15] + ")" + beforeGameTime +"<br>";
										}
										
										newbdvalue.rqps38hgtimes++;
									}
									
									NegativeRatioClient.betCtrMng.betLimitDvalues.add(newbdvalue);

								}
								
							}else {
								
								String dxfirstpankou = "";
								boolean first = true;
								boolean find = false;
								
								for(int k = 0; k < NegativeRatioClient.betCtrMng.betLimitDvalues.size(); k++) {
									
									BetDvalue bdvalue = NegativeRatioClient.betCtrMng.betLimitDvalues.elementAt(k);
									
									if(bdvalue.eventid.equals(item1[18]) && 
											bdvalue.dxbettype.length() >=3 &&
										bdvalue.dxbettype.substring(2).equals(item1[5].substring(2)) 
									   
									   
											){
										
										if(first == true) {
											dxfirstpankou = bdvalue.dxbetpankou;
											first = false;
										}
										
										if( bdvalue.dxbettype.equals(item1[5]) &&
												bdvalue.betscore.equals(item1[14]) &&
											Math.abs(Double.parseDouble(bdvalue.dxbetpankou) - Double.parseDouble(item1[6])) < 0.01) {
//											if(item1[19].equals("1")) {
//												bdvalue.dxhgps38times++;
//											}else if(item1[19].equals("2")) {
//												bdvalue.dxps38hgtimes++;
//											}
											
											if(item1[19].equals("1")) {									
												if(bdvalue.dxhgps38times==0) {
													bdvalue.dxhgps38timestr = "<html>" + item1[8] + "(" + item1[15] + ")" +beforeGameTime +  "<br>";
												}else {
													bdvalue.dxhgps38timestr += item1[8] + "(" + item1[15] + ")" +beforeGameTime +  "<br>";
												}
												
												bdvalue.dxhgps38times++;
											}else if(item1[19].equals("2")) {
												
												if(bdvalue.dxps38hgtimes==0) {
													bdvalue.dxps38hgtimestr = "<html>" + item1[8] + "(" + item1[15] + ")" +beforeGameTime +  "<br>";
												}else {
													bdvalue.dxps38hgtimestr += item1[8] + "(" + item1[15] + ")" + beforeGameTime + "<br>";
												}
												bdvalue.dxps38hgtimes++;
											}
											
											find = true;
											
											break;
											
										}
										
										

										
										
										
									}
									
									
									

									
								}
								
								
								boolean newtype = false;
								
								if(dxfirstpankou.equals("")) {
									newtype = true;
								}
								
								
								
								
								if(newtype ||
										(find == false && Math.abs(Double.parseDouble(dxfirstpankou) - Double.parseDouble(item1[6])) <= maxdvalue)) {
									BetDvalue newbdvalue = new BetDvalue();
									newbdvalue.betscore = item1[14];
									newbdvalue.dxbettype = item1[5];
									newbdvalue.dxbetpankou = item1[6];
									newbdvalue.eventid = item1[18];
//									if(item1[19].equals("1")) {
//										newbdvalue.dxhgps38times++;
//									}else if(item1[19].equals("2")) {
//										newbdvalue.dxps38hgtimes++;
//									}
									
									if(item1[19].equals("1")) {									
										if(newbdvalue.dxhgps38times==0) {
											newbdvalue.dxhgps38timestr = "<html>" + item1[8] + "(" + item1[15] + ")" +beforeGameTime +  "<br>";
										}else {
											newbdvalue.dxhgps38timestr += item1[8] + "(" + item1[15] + ")" +beforeGameTime +  "<br>";
										}
										
										newbdvalue.dxhgps38times++;
									}else if(item1[19].equals("2")) {										
										if(newbdvalue.dxps38hgtimes==0) {
											newbdvalue.dxps38hgtimestr = "<html>" + item1[8] + "(" + item1[15] + ")" + beforeGameTime + "<br>";
										}else {
											newbdvalue.dxps38hgtimestr += item1[8] + "(" + item1[15] + ")" +beforeGameTime +  "<br>";
										}
										newbdvalue.dxps38hgtimes++;
									}
									
									NegativeRatioClient.betCtrMng.betLimitDvalues.add(newbdvalue);

								}
								
								
								
							}
							
							
							

							
						}
						
					}
					
				}
				
				//todo  fill whole bdvalue
				
				int wholehgps38times = 0;
				int wholeps38hgtimes = 0;
				
				int dxwholehgps38times = 0;
				int dxwholeps38hgtimes = 0;
				
				String rqdvalue = "";
				String dxdvalue = "";
				
				for(int k = 0; k < NegativeRatioClient.betCtrMng.betLimitDvalues.size(); k++) {
					
					BetDvalue bdvalue = NegativeRatioClient.betCtrMng.betLimitDvalues.elementAt(k);
					
					if(bdvalue.eventid.equals(item[18]) && 
						bdvalue.rqbettype.contains("让球") 
					   ){
						

						wholehgps38times += bdvalue.rqhgps38times;
						wholeps38hgtimes += bdvalue.rqps38hgtimes;
						
						
						
						
					}
					
					if(bdvalue.eventid.equals(item[18]) && 
							bdvalue.dxbettype.contains("大小") 
						   ){
							

						dxwholehgps38times += bdvalue.dxhgps38times;
						dxwholeps38hgtimes += bdvalue.dxps38hgtimes;							
						}				
				}
				

				if(wholehgps38times < wholeps38hgtimes) {					
					rqdvalue = item[4].split("-vs-")[1] + " " +  limitStr.get(item[4]+item[5]);
				}else {
					rqdvalue = item[4].split("-vs-")[0] + " " + limitStr.get(item[4]+item[5]);
				}
			


				if(dxwholehgps38times < dxwholeps38hgtimes) {						
					dxdvalue = "小" + " " + limitStr.get(item[4]+item[5]);
				}else {
					dxdvalue = "大" + " " + limitStr.get(item[4]+item[5]);
				}
				

				
				BetDvalue bdvalue = new BetDvalue();
				boolean add = false;
				
				if(wholehgps38times != 0 || wholeps38hgtimes != 0) {
					
					bdvalue.rqdvalue = rqdvalue;
					add = true;
				}
				
				if(dxwholehgps38times != 0 || dxwholeps38hgtimes != 0) {
					
					bdvalue.dxdvalue = dxdvalue;
					add = true;
				}
				
				if(add == true) {
					NegativeRatioClient.betCtrMng.betLimitDvalues.add(bdvalue);
				}
				
				
			}
			
			
			//服务器不投特殊投注
			
			Vector<BetDvalue> bets = new Vector<BetDvalue>();
			
			for(int i = 0;i < NegativeRatioClient.betCtrMng.betLimitDvalues.size();i++) {
				bets.add(NegativeRatioClient.betCtrMng.betLimitDvalues.elementAt(i));
			}
			
			Vector<BetDvalue> bets1 = new Vector<BetDvalue>();
			
			for(int i = 0;i < NegativeRatioClient.betCtrMng.betLimitDvalues.size();i++) {
				bets1.add(NegativeRatioClient.betCtrMng.betLimitDvalues.elementAt(i));
			}
			
//			SpecialServer.mainWnd.updateBetDvalueTable(bets);
//			
			//SpecialServer.mainWnd.updateBetDvalueTable1(bets1);
			
			
			NegativeRatioClient.mainWnd.updateBetLimitDvalueTable(bets);
			
			
//			for(int i =0; i < SpecialServer.betCtrMng.betLimitDvalues.size();i++ ) {
//				System.out.println(SpecialServer.betCtrMng.betLimitDvalues.elementAt(i).tostring());
//				
//			}
			
			
		}catch(Exception e) {
			e.printStackTrace();
		}
		
		
		betDvaluesLock.writeLock().unlock();

	}
	
	
	
	
	
	
	
    public void setOneRowBackgroundColor() {
    	

    	
        try {  
        	
            DefaultTableCellRenderer tcr = new DefaultTableCellRenderer() {
            	
            	
  
                public Component getTableCellRendererComponent(JTable table,  
                        Object value, boolean isSelected, boolean hasFocus,  
                        int row, int column) {  

                	
                    if (row%2==1) {  
                    	setBackground(new Color(246,246,246));  
                        
                    }else{  
                        setBackground(new Color(222,222,243));  
                    	//setBackground(new Color(1,1,1));  
                      
                    }  
                    
                    setHorizontalAlignment(JLabel.CENTER);
  
                    return super.getTableCellRendererComponent(table, value,  
                            isSelected, hasFocus, row, column);  
                }  
            };  
            
            
            DefaultTableCellRenderer resRender = new DefaultTableCellRenderer() {   

                public void setValue(Object value) { //重写setValue方法，从而可以动态设置列单元字体颜色   

                   
                	String str = value.toString();
                	
    				
    				
    				if(str.contains("成功")){
    					
    					setBackground(Color.GREEN);

    				}else if(str.contains("失败")){    	
    					setBackground(Color.red);
    				}else {
    					setBackground(Color.yellow);
    				}
    				
    				if(str.contains("!")) {
    					setBackground(new Color(147, 112, 219));
    				}
    				
    				
    				setForeground(Color.BLACK);
    					
    				setText((value == null) ? "" : str);
    				
    				 setHorizontalAlignment(JLabel.CENTER);

                }   

            };  
            
            
            
            
            DefaultTableCellRenderer ratioRender = new DefaultTableCellRenderer() {   

                public void setValue(Object value) { //重写setValue方法，从而可以动态设置列单元字体颜色   

                   
                	String str = value.toString();
                	
                	
                	setForeground(Color.BLACK);
                	
    				if(Common.isNum(str)) {
    					double ratio = Double.parseDouble(str);
    					if(ratio - NegativeRatioClient.mainWnd.getbetodd() < 0.0) {
    						setForeground(Color.red);
    	    				
    					}
    				}
    				
    				//setBackground(new Color(246,246,246)); 
    				
    				
    					
    				setText((value == null) ? "" : str);
    				
    				 setHorizontalAlignment(JLabel.CENTER);

                } 
                
                
                public Component getTableCellRendererComponent(JTable table,  
                        Object value, boolean isSelected, boolean hasFocus,  
                        int row, int column) {  

                	
                    if (row%2==1) {  
                    	setBackground(new Color(246,246,246));  
                        
                    }else{  
                        setBackground(new Color(222,222,243));  
                    	//setBackground(new Color(1,1,1));  
                      
                    }  
                    
                    setHorizontalAlignment(JLabel.CENTER);
  
                    return super.getTableCellRendererComponent(table, value,  
                            isSelected, hasFocus, row, column);  
                }  
                
                
                

            }; 
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            int columnCount = table.getColumnCount();  
            for (int i = 0; i < columnCount; i++) {  
            	
            	String columnname = table.getColumnName(i);
            	
            	if(columnname.equals("皇冠结果") || columnname.equals("结果")) {
            		table.getColumn(columnname).setCellRenderer(resRender);
            	//	continue;
            	}else if(columnname.equals("合并赔率")){
            		table.getColumn(columnname).setCellRenderer(ratioRender);
            		
            	}else {
            		table.getColumn(columnname).setCellRenderer(tcr);
            	}
            	
            	
            }  
        } catch (Exception ex) {  
            ex.printStackTrace();  
        }  
    
    }  
	
	
	
	

    public class MyTableModel extends AbstractTableModel  
    {  
        /**
		 * 
		 */
		private static final long serialVersionUID = 10086L;
		/* 
         * 这里和刚才一样，定义列名和每个数据的值 
         */  
        String[] columnNames =          
        	{ "序号", "时间","联赛", "比赛时间", "球队", "投注类型", "投注盘口",  "注单", "金额 ",  "结果", "投注比分","网址"};

  
        /** 
         * 构造方法，初始化二维数组data对应的数据 
         */  
        public MyTableModel()  
        {  

        }  
  
        // 以下为继承自AbstractTableModle的方法，可以自定义  
        /** 
         * 得到列名 
         */  
        @Override  
        public String getColumnName(int column)  
        {  
            return columnNames[column];  
        }  
          
        /** 
         * 重写方法，得到表格列数 
         */  
        @Override  
        public int getColumnCount()  
        {  
            return columnNames.length;  
        }  
  
        /** 
         * 得到表格行数 
         */  
        @Override  
        public int getRowCount()  
        {         
	        if(null == detailsData){
	    		return 0;
	    	}
            return detailsData.size();  
        }  
  
        /** 
         * 得到数据所对应对象 
         */  
        @Override  
        public Object getValueAt(int rowIndex, int columnIndex)  
        {  
            //return data[rowIndex][columnIndex];
        	return detailsData.elementAt(rowIndex)[columnIndex];
        }  
  
        /** 
         * 得到指定列的数据类型 
         */  
        @Override  
        public Class<?> getColumnClass(int columnIndex)  
        {  
        	
        	return String.class;
        	
//        	if(detailsData.size() == 0){
//        		return String.class;
//        	}
//
//            return detailsData.elementAt(0)[columnIndex].getClass();
        	
        }  
  
        /** 
         * 指定设置数据单元是否可编辑.这里设置"姓名","学号"不可编辑 
         */  
        @Override  
        public boolean isCellEditable(int rowIndex, int columnIndex)  
        {  
            return false;
        }  
          
        /** 
         * 如果数据单元为可编辑，则将编辑后的值替换原来的值 
         */  
        @Override  
        public void setValueAt(Object aValue, int rowIndex, int columnIndex)  
        {  
            detailsData.elementAt(rowIndex)[columnIndex] = (String)aValue;  
            /*通知监听器数据单元数据已经改变*/  
            fireTableCellUpdated(rowIndex, columnIndex);  
        }  
        
        public void updateTable(){
        	fireTableDataChanged();
        }
        
  
    }  
	
	
	
	
	
	
	
	
	
}
